using System;
using System.Collections.Generic;
using System.Text;
using EnvDTE80;
using Microsoft.VisualStudio.Shell.Interop;
using Koda.Search;

namespace Koda.Search.Finders
{
    public class MemberFinder : SymbolFinderBase
    {
        protected override _LIB_LISTTYPE ListType
        {
            get 
            {
                return _LIB_LISTTYPE.LLT_MEMBERS;
            }
        }

        protected override LIB_CATEGORY Category
        {
            get 
            {
                return LIB_CATEGORY.LC_MEMBERTYPE;
            }
        }

        public MemberFinder(DTE2 dte)
            : base(dte)
        {
        }

        protected override VsItemType GetVsItemType(uint value)
        {
            switch ((_LIBCAT_MEMBERTYPE)value)
            {
                case _LIBCAT_MEMBERTYPE.LCMT_METHOD:
                    return VsItemType.Method;

                case _LIBCAT_MEMBERTYPE.LCMT_PROPERTY:
                    return VsItemType.Property;

                case _LIBCAT_MEMBERTYPE.LCMT_FIELD:
                    return VsItemType.Field;

                case _LIBCAT_MEMBERTYPE.LCMT_CONSTANT:
                    return VsItemType.Constant;

                default:
                    return VsItemType.Unknown;
            }
        }

        protected override string ParseName(string fullName)
        {
            int startPosition = fullName.LastIndexOf("(");
            if (startPosition == -1)
                startPosition = fullName.Length - 1;

            int position = fullName.LastIndexOf('.', startPosition);
            if (position > -1 && (position + 1) < fullName.Length)
                return fullName.Substring(position + 1);
            return fullName;
        }
    }
}